package com.meilai.project.dto.business.intentionScheme;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;
import java.util.Objects;

/**
 * @author xchen
 * @since 2022-02-25
 */
@Data
@ApiModel
@EqualsAndHashCode
public class PointProcessDateRangeDTO {

	@NotNull
	@ApiModelProperty("开始日期")
	private LocalDate beginDate;

	@NotNull
	@ApiModelProperty("结束日期")
	private LocalDate endDate;

	@ApiModelProperty("index")
	private Integer index;

	@ApiModelProperty("套餐信息")
	private List<ComboInfo> comboInfoList;

	@NotNull
	@ApiModelProperty("包含的点位信息列表")
	private List<MediaPointSimpleVO> pointList;

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (!(o instanceof PointProcessDateRangeDTO)) return false;
		PointProcessDateRangeDTO that = (PointProcessDateRangeDTO) o;
		return beginDate.equals(that.beginDate) && endDate.equals(that.endDate) && pointList.equals(that.pointList);
	}

	@Data
	@ApiModel
	public static class ComboInfo implements Serializable {
		private Long building_area_id;
		private Long combo_id;
		private Long rule_id;
		private Long count;
	}

	@Override
	public int hashCode() {
		return Objects.hash(beginDate, endDate, pointList);
	}

	/**
	 * 两个区间是否重合
	 */
	public boolean isOverlap(PointProcessDateRangeDTO other) {
		//不和自己比较
		if (this == other) {
			return false;
		}
		if (other.getEndDate().compareTo(this.getEndDate()) > 0) {
			return other.getBeginDate().compareTo(this.getEndDate()) < 0;
		} else if (other.getEndDate().compareTo(this.getEndDate()) == 0) {
			return true;
		} else {
			return this.getBeginDate().compareTo(other.getEndDate()) < 0;
		}
	}
}
